Xbasic

regex_literal_mask_get Function

Syntax

C REGEX_LITERAL_MASK_GET(RegEx as c[,PlaceHolder as c[,options as c]])

Arguments

RegEx

Regular expression

PlaceHolder

Placeholder to plug in the dynamic parts of a regular expression.

options

Options for matching - only option at this point is '+' to expand ranges, which are normally collapsed.

Description

Get the literal characters from a regular expression - puts in optional placeholder for characters. The purpose is to extract out the parts of a regular expression which could be considered parts of a 'template'.

The purpose of this function is to allow regular expressions brought in to be converted to input templates.

Example

? regex_literal_mask_get("hello (a-z+) what a (a-z+) day","{tag}","+")
= "hello {tag} what a {tag} day"

' A regex pattern that resembles a phone number - note that there is one placeholder per dynamic run
? regex_literal_mask_get("[0-9]-\([0-9]{1,3}\) [0-9]{1,3} [0-9]{1,4}","{digit}","")
= "{digit}-({digit}) {digit} {digit}"

' The same pattern, but with a placholder for the maxed out range.
? regex_literal_mask_get("[0-9]-\([0-9]{1,3}\) [0-9]{1,3} [0-9]{1,4}","{digit}","+")
= "{digit}-({digit}{digit}{digit}) {digit}{digit}{digit} {digit}{digit}{digit}{digit}"

See Also